package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/api/v1/channel")
@RestController
public class AdChannelController implements AdChannelControllerApi {
    @Autowired
    AdChannelService adChannelService;

    /**
     * 展示
     * @param dto
     * @return
     */
    @Override
    @PostMapping("list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }

    /**
     * 添加
     * @param adChannel
     * @return
     */
    @Override
    @RequestMapping("add")
    public ResponseResult add(@RequestBody AdChannel adChannel) {
        return adChannelService.add(adChannel);
    }

    /**
     * 修改
     * @param adChannel
     * @return
     */
    @Override
    @RequestMapping("update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    @RequestMapping("/del/{id}")
    public ResponseResult del(@PathVariable("id") Integer id) {
        return adChannelService.del(id);
    }

    @Override
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
}
